<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        span{
            display: block;
            width: 200px;
            height: 200px;
            color: #fff;
            background-color: black;
        }
    </style>
</head>

<body>
    <span class="hour">1</span>
    <span class="minute">1</span>
    <span class="second">1</span>

    <script>
        var hour = document.querySelector('.hour') //装小时的盒子
        var minute = document.querySelector('.minute')//装分钟的盒子
        var second = document.querySelector('.second')//装秒数的盒子
        var inputTime = +new Date('2021-8-25 13:00:00'); //返回的是用户输入时间总的毫秒数
        // 2. 开启定时器
        countDown();
        setInterval(countDown,1000);

        //获取时间
        function countDown() {
        var nowTime = +new Date(); //返回的是当前时间总的毫秒数
        
        var times = (inputTime - nowTime) / 1000; // times是剩余时间总的秒数
        var h = parseInt(times / 60 / 60 % 24);//时
        h = h < 10 ? '0' + h : h;
        hour.innerHTML = h;//把剩余的小时给小时黑色盒子
        var m = parseInt(times / 60 % 60);//分
        m = m < 10 ? '0'+m :m ;
        minute.innerHTML = m;
        var s = parseInt(times % 60);//当前的秒
        s = s < 10 ? '0'+s : s;
        second.innerHTML = s;
        }
    </script>
</body>

</html>